﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.ServiceModel;
using System.ServiceModel.Activation;
using System.ServiceModel.Web;
using System.Text;
using MezmurStore2.Models;

namespace WcfRestService1
{
    // Start the service and browse to http://<machine_name>:<port>/Service1/help to view the service's generated help page
    // NOTE: By default, a new instance of the service is created for each call; change the InstanceContextMode to Single if you want
    // a single instance of the service to process all calls.	
    [ServiceContract]
    [AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)]
    [ServiceBehavior(InstanceContextMode = InstanceContextMode.PerCall)]
    // NOTE: If the service is renamed, remember to update the global.asax.cs file
    public class SongService
    {


        [WebGet(UriTemplate = "artist/?artist={artist}", RequestFormat = WebMessageFormat.Json,  ResponseFormat = WebMessageFormat.Json)]
        public List<Song> GetSongsByArtist(string artist)
        {
            var entities = new MezmurStoreEntities();
            return entities.Songs.Where( s => s.artist.ToLower().Contains(artist.ToLower())).ToList();
        }

        [WebGet(UriTemplate = "album/?album={album}", RequestFormat = WebMessageFormat.Json, ResponseFormat = WebMessageFormat.Json)]
        public List<Song> GetSongsByAlbum(string album)
        {
            var entities = new MezmurStoreEntities();
            return entities.Songs.Where(s => s.album.ToLower().Contains(album.ToLower())).ToList();
        }

        [WebGet(UriTemplate = "category/?category={category}", RequestFormat = WebMessageFormat.Json, ResponseFormat = WebMessageFormat.Json)]
        public List<Song> GetSongsByCategory(string category)
        {
            var entities = new MezmurStoreEntities();
            return entities.Songs.Where(s => s.category.ToLower().Contains(category.ToLower())).ToList();
        }


    }
}
